package com.lht.cozyCloud.bee.utils;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author lht
 * @version 1.0
 * @description: TODO
 * @date 2025/2/13 8:51
 */

@Configuration
public class BeeAsyncConfig implements AsyncConfigurer {
    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(5);  // 核心线程数
        threadPool.setMaxPoolSize(10);  // 最大线程数
        threadPool.setQueueCapacity(50);  // 队列容量
        threadPool.setThreadNamePrefix("BeeAsync-");  // 线程统一前缀
        threadPool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());  // 拒绝策略：退回调用者线程执行
        threadPool.initialize();
        return threadPool;
    }

}
